define(function(require,exports,module) { 
    var myPub = require('./public');

    var oCategorysBox = $('.js_categorysBox');          // 分类容器
    var oCategorysNavList = $('.js_categorysNavList');  // 导航列表父级
    var oSildeNavJRoll = new myPub.ScrollBar();         // 导航滚动条

    // 获取产品数据的路径
    var goodsDateUrl = 'static_v4/js/dataJson/goodsData.json';

    module.exports = {
        init:function(){
            oCategorysBox.find('.js_categorysDetail').eq(0).show();
            oCategorysNavList.find('li').eq(0).addClass('active');
            // categorysList.SetNavList(names);
            oSildeNavJRoll.AddScroll(oCategorysNavList[0]);

            // 产品懒加载  异步加载 调用这个
            myPub.lazLoadingImgEchoAbs($('.js_categorysDetail')[0]);
        }
    };

    // 点击导航展示对应容器
    oCategorysNavList.hammer().on('tap', function (e) {
        var tar = e.gesture.target;
        var $target = null;

        if(tar.tagName.toLowerCase() == 'li') {
            $target = $(tar);
            var index = $target.index();
            oCategorysNavList.find('li').removeClass('active');
            $target.addClass('active');
            oCategorysBox.find('.js_categorysDetail').hide().eq(index).show();

            myPub.lazLoadingImgEchoAbs($('.js_categorysDetail')[index]);

            // if(categorysList.loadOff[index]) {
            //     categorysList.loadOff[index] = false;
            //     categorysList.getDataList(index, function () {
            //         myPub.lazLoadingImgEchoAbs($('.js_categorysDetail')[index]);
            //     });
            // }
        }
    });

    var categorysList = {
        loadOff: [false],       // 加载开关
        /*设置导航*/
        SetNavList: function (name) {
            var _this = this;
            var shtmlNav = '';
            var shtmlBox = '';

            for (var i=0; i<name.length; i++) {
                shtmlNav += '<li>'+ name[i] +'</li>';
                shtmlBox += '<div class="categorysDetail js_categorysDetail" style="display: none;"></div>'
                _this.loadOff.push(true);
            }
            // 设置导航
            oCategorysNavList.find('ul').append(shtmlNav);
            // 设置产品容器
            oCategorysBox.append(shtmlBox);
            // 导航加滚动
            oSildeNavJRoll.AddScroll(oCategorysNavList[0]);
        },
        getDataList: function (index, fn) {
            var _this = this;
            G_JSON_GET(goodsDateUrl,{
                // "maxLimit":maxLimit
            },function (data) {
                var dataJson = data.goodsNew;
                if( data.status == "success") {
                    if(index != 0) {
                        _this.GoodsLiHtml(dataJson, index)
                    }
                    if(fn)fn()
                }
            }, function () {}, function () {});
        },
        GoodsLiHtml : function (dataJson, index) {
            var oGoodsBox = oCategorysBox.find('.js_categorysDetail').eq(index);
            var shtmlLi ='';
            var shtmlBox = '<div class="categorysGoods js_categorysGoods">'+
                                '<div class="goods_title">'+
                                    '<h5><span>小暑清凉</span></h5>'+
                                '</div>'+ 
                                '<div class="categorysGoodsList goodsList ">'+
                                    '<ul class="clearfix js_goodsListUl"></ul>'+
                                '</div>'+
                            '</div>';
            for (var i=0; i<dataJson.length; i++) {
                shtmlLi += '<li>'+
                                '<a href="">'+
                                    '<figure>'+
                                        '<img class="js_lazyImg" data-echo="static_v4/image/adsBg/categorysList.jpg" src="static_v4/image/loadImg.jpg" alt="">'+
                                    '</figure>'+
                                    '<aside class="priceArea">'+
                                        '<div class="priceArea_name">'+
                                            '<h4>西瓜</h4>'+
                                        '</div>'+
                                    '</aside>'+
                                '</a>'+
                            '</li>'
            }
            var oHtmlBox = $(shtmlBox);
            oGoodsBox.append(oHtmlBox);
            oHtmlBox.find('.js_goodsListUl').append(shtmlLi);
        }
    }
});